<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla controller library
jimport('joomla.application.component.controller');

/**
 * Hello World Component Controller
 */
class BookingControllerGetdata extends JController
{
	function resource_type()
	{
		echo "<select id=\"res_type\">
			<option value=\"Free\" selected>免費會議室</option>
			<option value=\"Charge\">收費會議室</option>
		</select>";
	}
	function resources()
	{
		$json = JRequest::get( 'post' );
		$type = JRequest::getString('res_type');
		//echo json_encode($json);
		
		$db = JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->select('id,resource_name');
		$query->from('#__booking_resources');
		$query->where('resource_type = "'.$type.'"');
		$db->setQuery((string)$query);
		$messages = $db->loadObjectList();
		$html = '<select id="res">';
		if ($messages)
		{
			foreach($messages as $message) 
			{
				$html = $html.'<option value='.$message->id.'>'.$message->resource_name.'</option>';
			}
		}
		$html = $html.'</select>';
		echo $html;	
		
	}
	
	function getResverations(){
		JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_booking'.DS.'tables');
		$r = JRequest::get( 'get' );
		//$json = json_decode($r['content']);
		$table =  JTable::getInstance('reservations', 'Table');
		//$rows = $table->getReservations($json->resource_id,$json->start_time,$json->end_time);
		$rows = $table->getReservations($r['resource_id'],$r['start_time'],$r['end_time']);
		echo json_encode($rows);
		
	}
	function test()
	{
		$json = JRequest::get( 'post' );
		//echo $json;
		echo json_encode($json);
	}
}
?>